<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<html>
<head>
    <title>管理员查询</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/layui.css" />
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/common.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/slide.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/flat-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/jquery.nouislider.css">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/layui.js" media="all" ></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
        $(function(){
            $.ajax({
                type:"get",
                url:"${pageContext.request.contextPath }/admin/goLimit",
                data:{
                    pageNum:1
                },
                dataType:"json",
                success:function(data){
                    console.log(data);
                    var tr="";
                    $.each(data.list, function(index,info) {
                        tr+="<tr><td>"+info.adminId+"</td><td>"+info.adminName+"</td>"+
                            "<td><img src='../img/"+info.avatar+" 'width='100px' height='100px'/></td>"+
                            "<td>"+info.email+"</td>"+"<td>"+info.adminPassword+"</td>"+
                            "<td>"+info.phone+"</td>"+"<td>"+info.sex+"</td>"+
                            "<td>"+info.loginIp+"</td>"+
                            "<td>"+info.createTime+"</td>"+"<td>"+info.updateTime+"</td>"+
                            "<td><button id='updateAdmin' class='btn btn-success btn-xs' data-toggle='modal' data-target='#update' value='"+info.adminId+" '>修改</button>"+
                            "<button class='btn btn-danger btn-xs ' data-toggle='modal'value='"+info.adminId+" 'id='del'>删除</button></td>"+
                            "<tr/>";
                    })
                    $("#table-list").append(tr);
                    $("#prev").val(data.hasPreviousPage);
                    $("#next").val(data.hasNextPage);
                    $("#nowPage").val(data.pageNum);

                }
            });

            $("#p-button").on("click", "#bt", function(){
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/goLimit",
                    data:{
                        pageNum:$(this).val()
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        $("#prev").val(data.hasPreviousPage);
                        $("#next").val(data.hasNextPage);
                        $("#nowPage").val(data.pageNum);
                        var tr="";
                        $.each(data.list, function(index,info) {
                            tr+="<tr><td>"+info.adminId+"</td><td>"+info.adminName+"</td>"+
                                "<td><img src='../img/"+info.avatar+" 'width='100px' height='100px'/></td>"+
                                "<td>"+info.email+"</td>"+"<td>"+info.adminPassword+"</td>"+
                                "<td>"+info.phone+"</td>"+"<td>"+info.sex+"</td>"+
                                "<td>"+info.loginIp+"</td>"+
                                "<td>"+info.createTime+"</td>"+"<td>"+info.updateTime+"</td>"+
                                "<td><button id='updateAdmin' class='btn btn-success btn-xs' data-toggle='modal' data-target='#update' value='"+info.adminId+" '>修改</button>"+
                                "<button class='btn btn-danger btn-xs ' data-toggle='modal'value='"+info.adminId+" 'id='del'>删除</button></td>"+
                                "<tr/>";
                        })
                            $("#table-list").html(tr);


                    }
                });
            });

            //上一页
            $("#prev").click(function () {
                var pageNum = 0;
                if ($(this).val()=="false"){
                    pageNum = $("#nowPage").val();
                }else if($(this).val()=="true"){
                    pageNum =  $("#nowPage").val()-1;
                }
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/goLimit",
                    data:{
                        pageNum:pageNum
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        var tr="";
                        $.each(data.list, function(index,info) {
                            tr+="<tr><td>"+info.adminId+"</td><td>"+info.adminName+"</td>"+
                                "<td><img src='../img/"+info.avatar+"'width='100px' height='100px'/></td>"+
                                "<td>"+info.email+"</td>"+"<td>"+info.adminPassword+"</td>"+
                                "<td>"+info.phone+"</td>"+"<td>"+info.sex+"</td>"+
                                "<td>"+info.loginIp+"</td>"+
                                "<td>"+info.createTime+"</td>"+"<td>"+info.updateTime+"</td>"+
                                "<td><button id='updateAdmin' class='btn btn-success btn-xs' data-toggle='modal' data-target='#update' value='"+info.adminId+" '>修改</button>"+
                                "<button class='btn btn-danger btn-xs ' data-toggle='modal'value='"+info.adminId+" 'id='del'>删除</button></td>"+
                                "<tr/>";
                        })
                        $("#table-list").html(tr);
                        $("#prev").val(data.hasPreviousPage);
                        $("#next").val(data.hasNextPage);
                        $("#nowPage").val(data.pageNum);
                    }
                });
            })


            // 下一页
            $("#next").click(function () {
                console.log($(this).val())
                var pageNum = 0;
                if ($(this).val()=="false"){
                    pageNum = $("#nowPage").val();
                }else if($(this).val()=="true"){
                    pageNum = parseInt($("#nowPage").val())+1;
                    console.log(pageNum)
                }
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/goLimit",
                    data:{
                        pageNum:pageNum
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        var tr="";
                        $.each(data.list, function(index,info) {
                            tr+="<tr><td>"+info.adminId+"</td><td>"+info.adminName+"</td>"+
                                "<td><img src='../img/"+info.avatar+" 'width='100px' height='100px'/></td>"+
                                "<td>"+info.email+"</td>"+"<td>"+info.adminPassword+"</td>"+
                                "<td>"+info.phone+"</td>"+"<td>"+info.sex+"</td>"+
                                "<td>"+info.loginIp+"</td>"+
                                "<td>"+info.createTime+"</td>"+"<td>"+info.updateTime+"</td>"+
                                "<td><button id='updateAdmin' class='btn btn-success btn-xs' data-toggle='modal' data-target='#update' value='"+info.adminId+" '>修改</button>"+
                                "<button class='btn btn-danger btn-xs ' data-toggle='modal'value='"+info.adminId+" 'id='del'>删除</button></td>"+
                                "<tr/>";
                        })
                        $("#table-list").html(tr);
                        $("#prev").val(data.hasPreviousPage);
                        $("#next").val(data.hasNextPage);
                        $("#nowPage").val(data.pageNum);
                    }
                });
            })
            $("#search").click(function () {
                $.ajax({
                    type:"get",
                    url: "${pageContext.request.contextPath}/admin/adminBy",
                    dataType: "json",
                    data: {
                        keyword: $("#keyword").val()
                    },
                    success: function (data) {
                        if (data != "") {
                            var tr = "";
                            $.each(data, function (index, info) {
                                tr+="<tr><td>"+info.adminId+"</td><td>"+info.adminName+"</td>"+
                                    "<td><img src='../img/"+info.avatar+" 'width='100px' height='100px'/></td>"+
                                    "<td>"+info.email+"</td>"+"<td>"+info.adminPassword+"</td>"+
                                    "<td>"+info.phone+"</td>"+"<td>"+info.sex+"</td>"+
                                    "<td>"+info.loginIp+"</td>"+
                                    "<td>"+info.createTime+"</td>"+"<td>"+info.updateTime+"</td>"+
                                    "<td><button id='updateAdmin' class='btn btn-success btn-xs' data-toggle='modal' data-target='#update' value='"+info.adminId+" '>修改</button>"+
                                    "<button class='btn btn-danger btn-xs ' data-toggle='modal'value='"+info.adminId+" 'id='del'>删除</button></td>"+
                                    "<tr/>";
                            })
                            $("#table-list").html(tr);
                            $("#prev").val(data.hasPreviousPage);
                            $("#next").val(data.hasNextPage);
                            $("#nowPage").val(data.pageNum);
                        }else {
                            alert("没有这个管理员");
                        }

                    }

                })

            });
            //删除
            $("#table-list").on("click", "#del", function() {
                console.log($(this).val())
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/del",
                    data:{
                        adminId:$(this).val(),
                        isDel:1
                    },
                    dataType:"json",
                    success:function(data){
                        if (data==1){
                            alert("删除成功")
                        }else {
                            alert("删除失败")
                        }
                        location.href="${pageContext.request.contextPath}/admin/go";
                    }
                });

            });
            $("#table-list").on("click", "#updateAdmin", function() {
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/goUpdate",
                    data:{
                        adminId:$(this).val()
                    },
                    dataType:"json",
                    success:function(data){
                        console.log(data);
                        $("#adminId").val(data.adminId);
                        $("#adminName").val(data.adminName);
                        $("#avatar").val(data.avatar);
                        $("#email").val(data.email);
                        $("#adminPassword").val(data.adminPassword);
                        $("#phone").val(data.phone);
                        $("#sex").val(data.sex);
                        $("#loginIp").val(data.loginIp);
                        $("#updateTime").val(data.updateTime);
                         $("#isDel").val(data.isDel)
                    }
                });

            });
            $("#doupdateS").click(function () {
                console.log($("#adminId").val());
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/doUpdate",
                    data:{
                        adminId:$("#adminId").val(),
                        adminName:$("#adminName").val(),
                        avatar:$("#avatar").val(),
                        email:$("#email").val(),
                        adminPassword:$("#adminPassword").val(),
                        phone:$("#phone").val(),
                        sex:$("#sex").val(),
                        loginIp:$("#loginIp").val(),
                        updateTime:$("#updateTime").val(),
                        createTime:$("#createTime").val(),
                        isDel:$("#isDel").val()
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        if (data!=null){
                            alert("修改成功");
                            window.location.href = "${pageContext.request.contextPath}/admin/go";
                        }
                    }
                });
            });
            $("#ad").click(function(){
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath}/admin/addAdmin",
                    dataType:"text",
                    data:{
                        adminId:$("#adminIds").val(),
                        adminName:$("#adminNames").val(),
                        avatar:$("#avatars").val(),
                        email:$("#emails").val(),
                        adminPassword:$("#adminPasswords").val(),
                        phone:$("#phones").val(),
                        sex:$("#sexs").val(),
                        loginIp:$("#loginIps").val(),

                    },
                    success:function(data){
                        if (data==1) {
                            alert("添加成功");
                            location.href="${pageContext.request.contextPath}/admin/go";
                        }
                    }, error:function(){
                        alert("系统崩溃！");
                    }
                });
            })


        });
    </script>
</head>
<body>
<div role="tabpanel" class="tab-pane" id="stud">
    <div class="check-div form-inline">

        <div class="col-xs-3" style="padding-top: 25px">
            <button class="btn btn-yellow btn-xs" data-toggle="modal" data-target="#myModalAdd" >添加管理员</button>
        </div>
        <div class="col-xs-3">
            <input type="text" class=" form-control input-sm" placeholder="输入文字搜索" style=" height: 30px!important;"  id="keyword">
            <button class="btn btn-white btn-xs " id="search">查 询 </button>
        </div>

    </div>


    <table class="table text-center" id="tab">
    <thead>
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>头像</th>
        <th>邮箱</th>
        <th>密码</th>
        <th>手机号</th>
        <th>性别</th>
        <th>IP地址</th>
        <th>更新时间</th>
        <th>创建时间</th>
        <th colspan="2">操作</th>
    </tr>
    </thead>
    <tbody id="table-list"  class="tablebody">

    </tbody>

    <tbody>
    <%--<tr class="text-center">
        <td colspan="12">
            <button data-target="#myModalAdd" data-toggle="modal">添加</button>

        </td>
    </tr>--%>
    </tbody>

</table>
</div>
<%--<!-- 模态框（Modal） -->
<div class="modal fade" id="update" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    修改用户
                </h4>
            </div>
            <div class="modal-body">
                <input type="hidden" id="adminId"/>
                名称：<input type="text" id="adminName" /><br/>
                头像：<input type="text" id="avatar" /><br/>
                邮箱：<input type="text" id="email" /><br/>
                密码：<input type="password" id="adminPassword" /><br/>
                性别：<select id="sex">
                <option value ="0">男</option>
                <option value ="1">女</option>
                </select><br>
                IP地址：<input type="text" id="loginIp" /><br/>
                手机号码：<input type="text" id="phone" /><br/>
                <input type="hidden" id="updateTime" value="<%=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(Calendar.getInstance().getTime())%>"/>
                <input type="hidden" id="createTime"/>
                <input type="hidden" id="isDel"/>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal" id="doupdateS">提交更改</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->


</div>--%>


<div class="modal fade" id="update" role="dialog" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">修改管理员</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <form class="form-horizontal">
                        <input type="hidden" id="adminId"/>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">管理员姓名：</label>
                            <div class="col-xs-8 ">
                                <input type="text" id="adminName" class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">管理员头像：</label>
                            <div class="col-xs-8 ">
                                <input type="text" id="avatar" class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">管理员密码：</label>
                            <div class="col-xs-8 ">
                                <input type="password" id="adminPassword" class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">手机号：</label>
                            <div class="col-xs-8 ">
                                <input type="text" id="phone" class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">邮箱：</label>
                            <div class="col-xs-8 ">
                                <input type="text" id="email" class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">性别：</label>
                            <div class="col-xs-8 ">
                                <select id="sex">
                                    <option value ="0">男</option>
                                    <option value ="1">女</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">Ip地址：</label>
                            <div class="col-xs-8 ">
                                <input type="text" id="loginIp" class="form-control input-sm duiqi" id="sLink" placeholder=""/>
                            </div>
                        </div>
                        <input type="hidden" id="updateTime" value="<%=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(Calendar.getInstance().getTime())%>"/>
                        <input type="hidden" id="createTime"/>
                        <input type="hidden" id="isDel"/>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-xs btn-white" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-green btn-xs" id="doupdateS">保 存</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<%--<!-- 模态框（Modal） -->
<div class="modal fade" id="myModalAdd" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabels">
                    添加用户
                </h4>
            </div>
            <div class="modal-body">
                <input type="hidden" id="adminIds"/>
                名称：<input type="text" id="adminNames" /><br/>
                头像：<input type="text" id="avatars" /><br/>
                邮箱：<input type="text" id="emails" /><br/>
                密码：<input type="password" id="adminPasswords" /><br/>
                性别：<select id="sexs">
                <option value ="0">男</option>
                <option value ="1">女</option>
            </select><br>
                IP地址：<input type="text" id="loginIps" /><br/>
                手机号码：<input type="text" id="phones" /><br/>
                <input type="hidden" id="updateTimes" value="<%=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(Calendar.getInstance().getTime())%>"/>
                <input type="hidden" id="createTimes"/>
                <input type="hidden" id="isDels"/>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal" id="ad">提交更改</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->--%>

<div class="modal fade" id="myModalAdd" role="dialog" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabels">添加管理员</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <form class="form-horizontal">
                        <input type="hidden" id="adminIds"/>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">管理员姓名：</label>
                            <div class="col-xs-8 ">
                                <input type="text" id="adminNames"  class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">管理员头像：</label>
                            <div class="col-xs-8 ">
                                <input type="text" id="avatars"  class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">管理员密码：</label>
                            <div class="col-xs-8 ">
                                <input type="password" id="adminPasswords" class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">手机号：</label>
                            <div class="col-xs-8 ">
                                <input type="text" id="phones"  class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">邮箱：</label>
                            <div class="col-xs-8 ">
                                <input type="text" id="emails" class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">性别：</label>
                            <div class="col-xs-8 ">
                                <select id="sexs">
                                    <option value ="0">男</option>
                                    <option value ="1">女</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-4 control-label">Ip地址：</label>
                            <div class="col-xs-8 ">
                                <input  type="text" id="loginIps" class="form-control input-sm duiqi" id="sLink" placeholder="">
                            </div>
                        </div>
                        <input type="hidden" id="updateTimes" value="<%=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(Calendar.getInstance().getTime())%>"/>
                        <input type="hidden" id="createTimes"/>
                        <input type="hidden" id="isDels"/>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-xs btn-white" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-xs btn-green">保 存</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
</div>
<p style="text-align: center" id="p-button">
    <button class="btn btn-info" id="prev">上一页</button>
    <button class="btn btn-info" id="bt" value="1">第1页</button>
    <button class="btn btn-info" id="bt" value="2">第2页</button>
    <button class="btn btn-info" id="bt" value="3">第3页</button>
    <button class="btn btn-info" id="next">下一页</button>
</p>
<input type="hidden" id="nowPage"/>
</body>
</html>
